﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SummonSoldier : MonoBehaviour {
    public GameObject troopLeaderPrefab;
    public GameObject WarFlagPrefab;

    public float finishTime;
    public float finishTimer = 0;

    public void TriggerMagic()
    {
        TroopLeader troopLeader= Instantiate(troopLeaderPrefab, transform.position, transform.rotation).GetComponent<TroopLeader>();
        troopLeader.vehicle.targetPosition = transform.position;
        troopLeader.vehicle.targetRotation = transform.rotation;
        
        WarFlag warFlag = Instantiate(WarFlagPrefab, transform.position, transform.rotation).GetComponent<WarFlag>();
        warFlag.origin = troopLeader.GetComponent<TroopLeader>().warFlgOrigin;
        troopLeader.warFlgOrigin.warFlag = warFlag;
    }

    private void Start()
    {
        TriggerMagic();

    }

    private void Update()
    {
        finishTimer += Time.deltaTime;
        if (finishTimer > finishTime)
        {
            Destroy(this);
        }
    }
}
